import { sessionStore } from 'store/dist/store.legacy'
const state = {
  catList: []
}

const mutations = {
  setCatList (state, data) {
    state.catList = data
    sessionStore.set('catList', data)
  }
}

const actions = {
  setCatList ({ commit, state }) {
    if (state.catList.length > 0) {
      return
    }
    let catList = sessionStore.get('catList')
    if (!catList) {
      let url = process.env.VUE_APP_getMenu_url
      window.axios.post(url).then((ret) => {
        commit('setCatList', ret.data)
      })
    } else {
      commit('setCatList', catList)
    }
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}